﻿@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}
<style>
    .body{
        font-family:"Helvetica Neue","Helvetica","Microsoft Yahei","微软雅黑","Lantinghei SC","STXihei","WenQuanYi Micro Hei",Arial,sans-serif;
        text-align:justify;margin:auto;font-size:14px;line-height:1.6em;
        color:#333;background:#fefefe;padding:15px;margin:30px auto;position: relative;
        -webkit-font-smoothing: antialiased;font-smoothing: antialiased;
    }

    article,footer,header,nav{margin:0 auto}
    article{margin-top:4em;margin-bottom:4em;min-height:400px}
    footer{margin-bottom:50px}
    video{margin:2em 0;border:1px solid #ddd}
    nav{font-size:.9em;font-style:italic;border-bottom:1px solid #ddd;padding:1em 0}
    nav p{margin:0}
    details{margin: 15px 0;}
    summary{cursor:pointer;padding: 4px;}
    summary:focus{outline: none;box-shadow: 0 0 3px #2196F3;}
    .h1,h1{font-size:2.2em;}
    .h2,h2{font-size:1.9em;}
    .h3,h3{font-size:1.6em;}
    .h4,h4{font-size:1.3em;}
    .h5,h5{font-size:1.2em;}
    .h6,h6{font-size:1.1em;}
    .h1,.h2,.h3,.h4,.h5,.h6,h1,h2,h3,h4,h5,h6{
        font-family:inherit;font-weight:500;color: #333;
        line-height: 1.2em;padding: 0.3em 0;margin: 0.8em 0 0.4em 0;
        word-break: break-all;
    }
    .h1,h1{letter-spacing: 1px;border-bottom: 1px solid #ddd;}
    .h2,h2{padding-bottom: 0.15em;}
    p{-webkit-hypens:auto;-moz-hypens:auto;hyphens:auto;margin:10px 0;}
    p,li,div,ul{word-wrap: break-all;}
    blockquote{margin-left:1em;padding:10px 15px;margin:10px 0 20px 0;border-left:10px solid #ddd;background: #f6f6f6;}
    blockquote p{margin:0;font-weight:400;}
    pre{display:block;padding:0;overflow:auto;margin:0 0 10px;font-size:1em;line-height:1.42857143;
        word-break:break-all;word-wrap:break-word;color:#333;background:none;border-radius:4px}
    code,kbd,pre,samp{
        font-family:Consolas,'Liberation Mono','Ubuntu Mono',Menlo,Courier,sans-serif;
    }
    a{color:#1980e6;text-decoration:none}
    a:hover{text-decoration:underline}
    a img{border:none}
    img{max-width: 100%;}
    h1 a,h1 a:hover{text-decoration:none}
    hr{border: 0 none;height: 4px;margin:1.2em 0;
        background: rgba(0, 0, 0, 0) url() repeat-x 0 0;
    }
@@media screen and (min-width: 900px) {
        body {width: 900px;}
    }
    ul,ol{padding:0.2em 0 0.2em 2em;}
    table {border-collapse: collapse;border-spacing: 0;margin-bottom: 20px;}
    table thead{background: #eee;}
    table td,table th{padding: .5em;border: 1px solid #ddd;line-height: 1.5;}
    .markdown-flow{background:#fff;padding: 15px;}
    .markdown-flow .label{color:#444;}
    .markdown-latex {
        text-align: center;font-size:1.3em;color: #000;
        margin-bottom: 1.5em;overflow: hidden;overflow-x:auto;
    }
    .latex-inline .katex-display{display:inline-block;font-size: 0.8em;}
    .markdown-menu ul{padding:0 10px 20px 20px;}
    .markdown-menu li{
        font-size:14px;list-style:none;
        line-height:1.8em;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;
    }
    .markdown-menu-h2{padding-left:2em;}
    .markdown-menu-h3{padding-left:4em;}
    .markdown-menu-h4{padding-left:6em;}
    .markdown-menu-h5{padding-left:8em;}
    .markdown-menu-h6{padding-left:10em;}

    .print-btn{
        position:absolute;padding:4px 20px;color:#444;font-size:1em;
        background:#eee;background:rgba(200,200,200,0.2);margin-top: -45px;right:15px;
    }
    .print-btn:hover{text-decoration: none;background: #14a2ff;color: #fff;}

    .hidden{display:none !important;}

    /*打印样式*/
@@media print {
    body{padding:0 1.5cm;margin:0 auto 10px auto;font-size:13px;}
    .print-btn{display: none;}
}

ol.linenums {
    padding-left: 2.5em;
}
ol.linenums li {
    list-style-type: decimal!important;
}
</style>
<div class="text-center">
    <h1>happy dogs</h1>
    <div class="card" style="padding:7px">
        <div class="alert alert-warning" role="alert">
            未配置食物文件 — 将不会触发脚本执行!
        </div>
        <div style="height:7px"></div>
        <table class="table table-primary table-bordered">
            <thead>
            <th>狗名</th>
            <th>耐饿秒数</th>
            <th>喂食位置</th>
            <th>命令</th>
            <th>呼叫Verb</th>
            <th>执行目录</th>
            <th>脚本参数</th>
            <th>上次饥饿</th>
            <th>上次喂食</th>
            <th>上次进食</th>
            <th>上次呼叫</th>
            </thead>
            <tbody>
                @foreach (var dog in Model.dogs)
                {
                    <tr>
                        <td>@dog.dog_name</td>
                        <td>@dog.hunger_endurance_second</td>
                        <td>@dog.food_file_path</td>
                        <td>@dog.script_after_die.command</td>
                        <td>@dog.script_after_die.verb</td>
                        <td>@dog.script_after_die.workdir</td>
                        <td>@dog.script_after_die.arguments</td>
                        <td>@dog.lasthungertime</td>
                        <td>@dog.lastsending</td>
                        <td>@dog.lasteattime</td>
                        <td>@dog.lastcrytime</td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    <div class="body">

        <h2 id="h2-u4F7Fu7528u8BF4u660E"><a name="使用说明" class="reference-link"></a><span class="header-link octicon octicon-link"></span>使用说明</h2><ul>
            <li>为了尽量轻量化，不使用任何数据库。</li>
            <li>使用NLOG只记录警告级别以上的日志。</li>
            <li>使用.net自带的appsettings.json作为配置。</li>
            <li>提供简单的web页面以便查看情况。</li>
        </ul>
        <h3 id="h3-u4E1Au52A1u7CFBu7EDFu6539u9020u8BF4u660E"><a name="业务系统改造说明" class="reference-link"></a><span class="header-link octicon octicon-link"></span>业务系统改造说明</h3><ul>
            <li>业务系统在有效的时间内，定时向 food_file_path写入当前的操作系统时间，也可以写入别的数据，如果太久没写入，狗将被饿死，取决于hunger_endurance_second的设置。</li>
            <li>下面是C#的写入样例:<pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code><span class="kwd">static</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> </span><span class="typ">Main</span><span class="pun">(</span><span class="kwd">string</span><span class="pun">[]</span><span class="pln"> args</span><span class="pun">)</span></code></li><li class="L1"><code><span class="pln">      </span><span class="pun">{</span></code></li><li class="L2"><code><span class="pln">          </span><span class="typ">Console</span><span class="pun">.</span><span class="typ">WriteLine</span><span class="pun">(</span><span class="str">"hi, i restarted just now"</span><span class="pun">);</span></code></li><li class="L3"><code><span class="pln">          </span><span class="kwd">while</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">true</span><span class="pun">)</span></code></li><li class="L4"><code><span class="pln">          </span><span class="pun">{</span></code></li><li class="L5"><code><span class="pln">              </span><span class="typ">Console</span><span class="pun">.</span><span class="typ">WriteLine</span><span class="pun">(</span><span class="str">"hi, i want to see you"</span><span class="pun">);</span></code></li><li class="L6"><code><span class="pln">              </span><span class="typ">File</span><span class="pun">.</span><span class="typ">WriteAllText</span><span class="pun">(</span><span class="str">"food_file.txt"</span><span class="pun">,</span><span class="pln"> </span><span class="typ">DateTime</span><span class="pun">.</span><span class="typ">Now</span><span class="pun">.</span><span class="typ">ToString</span><span class="pun">(</span><span class="str">"yyyy-MM-dd HH:mm:ss"</span><span class="pun">));</span></code></li><li class="L7"><code><span class="pln">              </span><span class="typ">Thread</span><span class="pun">.</span><span class="typ">Sleep</span><span class="pun">(</span><span class="lit">7000</span><span class="pun">);</span></code></li><li class="L8"><code><span class="pln">          </span><span class="pun">}</span></code></li><li class="L9"><code><span class="pln">          </span><span class="typ">Console</span><span class="pun">.</span><span class="typ">WriteLine</span><span class="pun">(</span><span class="str">"see you again later"</span><span class="pun">);</span></code></li><li class="L0"><code><span class="pln">      </span><span class="pun">}</span></code></li></ol></pre></li>
        </ul>
        <hr>
        <h3 id="h3-u672Cu7A0Bu5E8Fu914Du7F6E"><a name="本程序配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>本程序配置</h3><p>appsettings.json配置说明：</p>
<pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code><span class="pun">{</span></code></li><li class="L1"><code><span class="pln">  </span><span class="str">"port"</span><span class="pun">:</span><span class="pln"> </span><span class="lit">9003</span><span class="pun">,</span><span class="com">// web页面使用的端口，请使用不冲突的端口号。</span></code></li><li class="L2"><code><span class="pln">  </span><span class="str">"dogs"</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="pln"> </span><span class="com">// 要监控的程序在这里。</span></code></li><li class="L3"><code><span class="pln">    </span><span class="pun">{</span></code></li><li class="L4"><code><span class="pln">      </span><span class="str">"dog_name"</span><span class="pun">:</span><span class="pln"> </span><span class="str">"测试狗1"</span><span class="pun">,</span><span class="pln"> </span><span class="com">// 自定义的名称，方便识别监控哪些程序</span></code></li><li class="L5"><code><span class="pln">      </span><span class="str">"food_file_path"</span><span class="pun">:</span><span class="pln"> </span><span class="str">"d:\\happydog\\food_file_1.txt"</span><span class="pun">,</span><span class="pln"> </span><span class="com">// 喂食的文件，此文件必须存在，由业务系统生成并写入当前时间。</span></code></li><li class="L6"><code><span class="pln">      </span><span class="str">"hunger_endurance_second"</span><span class="pun">:</span><span class="pln"> </span><span class="str">"5"</span><span class="pun">,</span><span class="pln"> </span><span class="com">// 多长时间不进食，狗才会死亡。</span></code></li><li class="L7"><code><span class="pln">      </span><span class="str">"hunger_count"</span><span class="pun">:</span><span class="pln"> </span><span class="str">"1"</span><span class="pun">,</span><span class="pln"> </span><span class="com">// 默认就写1，狗死亡的次数，目前不启用此参数。</span></code></li><li class="L8"><code><span class="pln">      </span><span class="str">"script_after_die"</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">// 狗死亡后，触发的求救行为</span></code></li><li class="L9"><code><span class="pln">        </span><span class="str">"command"</span><span class="pun">:</span><span class="pln"> </span><span class="str">"pwsh pause"</span><span class="pun">,</span><span class="pln"> </span><span class="com">// 使用执行的名称</span></code></li><li class="L0"><code><span class="pln">        </span><span class="str">"arguments"</span><span class="pun">:</span><span class="pln"> </span><span class="str">""</span><span class="pun">,</span><span class="pln"> </span><span class="com">// 名称后面需要补入的参数</span></code></li><li class="L1"><code><span class="pln">        </span><span class="str">"script_workdir"</span><span class="pun">:</span><span class="pln"> </span><span class="str">""</span><span class="pun">,</span><span class="pln"> </span><span class="com">// 指令执行的当前目录</span></code></li><li class="L2"><code><span class="pln">        </span><span class="str">"verb"</span><span class="pun">:</span><span class="pln"> </span><span class="str">""</span><span class="pln"> </span><span class="com">// 执行模式，windows下runas代表超级管理员（请慎用，可能会弹窗）</span></code></li><li class="L3"><code><span class="pln">      </span><span class="pun">}</span></code></li><li class="L4"><code><span class="pln">    </span><span class="pun">},</span></code></li><li class="L5"><code><span class="pln">    </span><span class="pun">{</span></code></li><li class="L6"><code><span class="pln">      </span><span class="str">"dog_name"</span><span class="pun">:</span><span class="pln"> </span><span class="str">"测试狗2"</span><span class="pun">,</span></code></li><li class="L7"><code><span class="pln">      </span><span class="str">"food_file_path"</span><span class="pun">:</span><span class="pln"> </span><span class="str">"E:\\Repos\\happy-dog\\HappyDog\\WorkTest\\bin\\Debug\\net8.0\\food_file.txt"</span><span class="pun">,</span></code></li><li class="L8"><code><span class="pln">      </span><span class="str">"hunger_endurance_second"</span><span class="pun">:</span><span class="pln"> </span><span class="str">"15"</span><span class="pun">,</span></code></li><li class="L9"><code><span class="pln">      </span><span class="str">"hunger_count"</span><span class="pun">:</span><span class="pln"> </span><span class="str">"1"</span><span class="pun">,</span></code></li><li class="L0"><code><span class="pln">      </span><span class="str">"script_after_die"</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L1"><code><span class="pln">        </span><span class="str">"command"</span><span class="pun">:</span><span class="pln"> </span><span class="str">"kill -Name WorkTest && start WorkTest.exe"</span><span class="pun">,</span></code></li><li class="L2"><code><span class="pln">        </span><span class="str">"arguments"</span><span class="pun">:</span><span class="str">""</span><span class="pun">,</span></code></li><li class="L3"><code><span class="pln">        </span><span class="str">"script_workdir"</span><span class="pun">:</span><span class="pln"> </span><span class="str">"E:\\Repos\\happy-dog\\HappyDog\\WorkTest\\bin\\Debug\\net8.0\\"</span><span class="pun">,</span></code></li><li class="L4"><code><span class="pln">        </span><span class="str">"verb"</span><span class="pun">:</span><span class="pln"> </span><span class="str">""</span></code></li><li class="L5"><code><span class="pln">      </span><span class="pun">}</span></code></li><li class="L6"><code><span class="pln">    </span><span class="pun">}</span></code></li><li class="L7"><code><span class="pln">  </span><span class="pun">]</span></code></li><li class="L8"><code><span class="pun">}</span></code></li></ol></pre>

        <!-- /MarkDown Content -->
    </div>
</div>
